package com.d3works.apps.businessproduction.service;

import com.d3works.apps.account.service.analytic.AnalyticMoveLineService;
import com.d3works.apps.account.service.app.AppAccountService;
import com.d3works.apps.account.service.config.AccountConfigService;
import com.d3works.apps.base.service.CurrencyService;
import com.d3works.apps.base.service.PriceListService;
import com.d3works.apps.base.service.ProductMultipleQtyService;
import com.d3works.apps.base.service.app.AppBaseService;
import com.d3works.apps.base.service.pricing.PricingService;
import com.d3works.apps.base.service.tax.AccountManagementService;
import com.d3works.apps.base.service.tax.TaxService;
import com.d3works.apps.businessproject.service.SaleOrderLineProjectServiceImpl;
import com.d3works.apps.sale.db.PackLine;
import com.d3works.apps.sale.db.SaleOrder;
import com.d3works.apps.sale.db.SaleOrderLine;
import com.d3works.apps.sale.db.repo.SaleOrderLineRepository;
import com.d3works.apps.sale.service.app.AppSaleService;
import com.d3works.apps.sale.service.saleorder.SaleOrderService;
import com.d3works.apps.supplychain.service.app.AppSupplychainService;
import com.d3works.exception.D3worksException;
import com.google.inject.Inject;
import java.math.BigDecimal;

public class SaleOrderLineBusinessProductionServiceImpl extends SaleOrderLineProjectServiceImpl {

  @Inject
  public SaleOrderLineBusinessProductionServiceImpl(
      CurrencyService currencyService,
      PriceListService priceListService,
      ProductMultipleQtyService productMultipleQtyService,
      AppBaseService appBaseService,
      AppSaleService appSaleService,
      AccountManagementService accountManagementService,
      SaleOrderLineRepository saleOrderLineRepo,
      SaleOrderService saleOrderService,
      AppAccountService appAccountService,
      AnalyticMoveLineService analyticMoveLineService,
      AppSupplychainService appSupplychainService,
      AccountConfigService accountConfigService,
      PricingService pricingService,
      TaxService taxService) {
    super(
        currencyService,
        priceListService,
        productMultipleQtyService,
        appBaseService,
        appSaleService,
        accountManagementService,
        saleOrderLineRepo,
        appAccountService,
        analyticMoveLineService,
        appSupplychainService,
        accountConfigService,
        saleOrderService,
        pricingService,
        taxService);
  }

  @Override
  public SaleOrderLine createSaleOrderLine(
      PackLine packLine,
      SaleOrder saleOrder,
      BigDecimal packQty,
      BigDecimal conversionRate,
      Integer sequence)
      throws D3worksException {

    SaleOrderLine soLine =
        super.createSaleOrderLine(packLine, saleOrder, packQty, conversionRate, sequence);

    if (soLine != null && soLine.getProduct() != null) {
      soLine.setBillOfMaterial(soLine.getProduct().getDefaultBillOfMaterial());
    }
    return soLine;
  }
}
